package TestExercises02;

import java.util.Scanner;

public class PhonesTest {
    public static void main(String[] args) {
        //1、创建一个数组
        Phones[] arr = new Phones[3];

        //2、创建手机对象，数据来自于键盘录入
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            Phones phones = new Phones();
            //录入品牌
            System.out.println("请输入手机的品牌：");
            String brand = sc.next();
            phones.setBrand(brand);

            //录入价格
            System.out.println("请输入手机的价格：");
            int price = sc.nextInt();
            phones.setPrice(price);

            //录入颜色
            System.out.println("请输入手机的颜色：");
            String color = sc.next();
            phones.setColor(color);

            arr[i] = phones;
        }

        //3、求三部手机价格的总和
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            Phones phone = arr[i];
            sum = sum + phone.getPrice();
        }

        //4、求平均价格
        double avg = sum * 1.0 / arr.length;
        System.out.println("手机的平均价格为：" + avg);
    }
}
